<template>
  <div>
    <Row :gutter="10">
      <Form v-model="formValidate"
            ref="formValidate"
            :label-width="160"
            style='margin-left:10px'>
        <FormItem label="自动收货天数"
                  prop="order_receive"
                  class="label_required">
          <Input v-model="formValidate.order_receive"
                 placeholder="请输入订单自动确认收货天数" style="width: 300px"/>
        </FormItem>
        <FormItem label="售后天数"
                  prop="order_success"
                  class="label_required">
          <Input v-model="formValidate.order_success"
                 placeholder="请输入订单售后天数" style="width: 300px"/>
        </FormItem>
        <FormItem>
          <Button type="primary"
                  @click="handleSubmit()"
                  style="width: 90px;height: 35px;border-radius: 0;font-size: 14px;">提交</Button>
        </FormItem>
      </Form>
    </Row>
  </div>
</template>
<script>
import { saveSettingInfo, getSettingInfo } from '@/api/main'
export default {
  data () {
    return {
      formValidate: {
        order_receive: 0,
        order_success: 0
      },
    }
  },
  methods: {
    handleSubmit () {
      if (!parseInt(this.formValidate.order_receive)) {
        this.$Message.error("请输入订单自动确认收货天数"); return;
      }
      if (!parseInt(this.formValidate.order_success)) {
        this.$Message.error("请输入订单售后天数"); return;
      }
      saveSettingInfo(this.formValidate).then(res => {
        if (res.code == 0) {
          this.$Message.success('保存成功')
        } else {
          this.$Message.error(res.text)
        }
      })
    }
  },
  mounted () {
    getSettingInfo().then(res => {
      if (res.code == 0) {
        this.formValidate.order_receive = res.data.order_receive
        this.formValidate.order_success = res.data.order_success
      } else {
        this.$Message.error(res.text)
      }
    })
  },
}
</script>
